import 'package:flutter/material.dart';
import 'package:flutter_learning/isolate/utils/ly_log.dart';
import 'package:flutter_learning/utils/ly_app_color.dart';
import 'package:flutter_learning/widgets/ly_sliver_table.dart';

class LYCustomScrollview extends StatefulWidget {
  const LYCustomScrollview({super.key});

  @override
  State<LYCustomScrollview> createState() => _LYCustomScrollviewState();
}

class _LYCustomScrollviewState extends State<LYCustomScrollview> {
  @override
  Widget build(BuildContext context) {
    List<SliverTableRow> rows = [];
    for (int i = 0; i < 10; i++) {
      List<SliverTableItem> rowItems = [];
      for (int j = 0; j < 6; j++) {
        rowItems.add(SliverTableItem(
            content: "$j-$i", canClick: j == 1, indexPath: LYIndexPath(row: i, column: j)));
      }
      final row = SliverTableRow(items: rowItems);
      rows.add(row);
    }
    return CustomScrollView(
      slivers: [
        // 其他 sliver 组件（如标题栏）
        SliverAppBar(
          title: Text("CustomScrollView with Table"),
          floating: true,
        ),

        // 用 SliverToBoxAdapter 包裹 Table
        LYSliverTable(
          columnWidths: {
            0: FixedColumnWidth(80),
            1: FixedColumnWidth(80),
            2: FixedColumnWidth(80),
            3: FixedColumnWidth(80),
            4: FixedColumnWidth(80),
            5: FixedColumnWidth(80),
          },
          titles: ["标题1", "标题2", "标题3", "标题4", "标题5", "标题6"],
          rows: rows,
          onClick: (indexPath) {
            LYLog.d(indexPath);
          },
        ),
        // 其他 sliver 组件（如列表）
        SliverList(
          delegate: SliverChildBuilderDelegate(
            (context, index) => ListTile(
              title: Text("Item ${index + 1}"),
            ),
            childCount: 20,
          ),
        ),
      ],
    );
  }
}
